Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/mozilla/cxxalloc.h
Warning:line 51, column 10
Attempt to free released memory

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name AccessibleWrap.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/accessible/atk -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/accessible/atk -resource-dir /usr/lib/llvm-19/lib/clang/19 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/accessible/atk -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/accessible/atk -I /var/lib/jenkins/workspace/firefox-scan-build/accessible/base -I /var/lib/jenkins/workspace/firefox-scan-build/accessible/generic -I /var/lib/jenkins/workspace/firefox-scan-build/accessible/html -I /var/lib/jenkins/workspace/firefox-scan-build/accessible/ipc -I /var/lib/jenkins/workspace/firefox-scan-build/accessible/xpcom -I /var/lib/jenkins/workspace/firefox-scan-build/accessible/xul -I /var/lib/jenkins/workspace/firefox-scan-build/layout/generic -I /var/lib/jenkins/workspace/firefox-scan-build/other-licenses/atk-1.0 -I /var/lib/jenkins/workspace/firefox-scan-build/widget -I /var/lib/jenkins/workspace/firefox-scan-build/widget/gtk -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/chromium/src -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -I /usr/include/gtk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/cloudproviders -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/gtk-3.0/unix-print -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-error=unused-function -Wno-unused-local-typedefs -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2024-09-22-115206-3586786-1 -x c++ /var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp

/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp

1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=2 et sw=2 tw=80: */
3/* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7#include "AccessibleWrap.h"
8
9#include "LocalAccessible-inl.h"
10#include "AccAttributes.h"
11#include "ApplicationAccessibleWrap.h"
12#include "InterfaceInitFuncs.h"
13#include "nsAccUtils.h"
14#include "mozilla/a11y/PDocAccessible.h"
15#include "OuterDocAccessible.h"
16#include "RemoteAccessible.h"
17#include "DocAccessibleParent.h"
18#include "RootAccessible.h"
19#include "mozilla/a11y/TableAccessible.h"
20#include "mozilla/a11y/TableCellAccessible.h"
21#include "nsMai.h"
22#include "nsMaiHyperlink.h"
23#include "nsString.h"
24#include "nsStateMap.h"
25#include "mozilla/a11y/Platform.h"
26#include "Relation.h"
27#include "RootAccessible.h"
28#include "States.h"
29#include "nsISimpleEnumerator.h"
30
31#include "mozilla/ArrayUtils.h"
32#include "mozilla/Sprintf.h"
33#include "nsAccessibilityService.h"
34#include "nsComponentManagerUtils.h"
35
36using namespace mozilla;
37using namespace mozilla::a11y;
38
39MaiAtkObject::EAvailableAtkSignals MaiAtkObject::gAvailableAtkSignals =
40 eUnknown;
41
42// defined in ApplicationAccessibleWrap.cpp
43extern "C" GType g_atk_hyperlink_impl_type;
44
45/* MaiAtkObject */
46
47enum {
48 ACTIVATE,
49 CREATE,
50 DEACTIVATE,
51 DESTROY,
52 MAXIMIZE,
53 MINIMIZE,
54 RESIZE,
55 RESTORE,
56 LAST_SIGNAL
57};
58
59enum MaiInterfaceType {
60 MAI_INTERFACE_COMPONENT, /* 0 */
61 MAI_INTERFACE_ACTION,
62 MAI_INTERFACE_VALUE,
63 MAI_INTERFACE_EDITABLE_TEXT,
64 MAI_INTERFACE_HYPERTEXT,
65 MAI_INTERFACE_HYPERLINK_IMPL,
66 MAI_INTERFACE_SELECTION,
67 MAI_INTERFACE_TABLE,
68 MAI_INTERFACE_TEXT,
69 MAI_INTERFACE_DOCUMENT,
70 MAI_INTERFACE_IMAGE, /* 10 */
71 MAI_INTERFACE_TABLE_CELL
72};
73
74static GType GetAtkTypeForMai(MaiInterfaceType type) {
75 switch (type) {
76 case MAI_INTERFACE_COMPONENT:
77 return ATK_TYPE_COMPONENT(atk_component_get_type ());
78 case MAI_INTERFACE_ACTION:
79 return ATK_TYPE_ACTION(atk_action_get_type ());
80 case MAI_INTERFACE_VALUE:
81 return ATK_TYPE_VALUE(atk_value_get_type ());
82 case MAI_INTERFACE_EDITABLE_TEXT:
83 return ATK_TYPE_EDITABLE_TEXT(atk_editable_text_get_type ());
84 case MAI_INTERFACE_HYPERTEXT:
85 return ATK_TYPE_HYPERTEXT(atk_hypertext_get_type ());
86 case MAI_INTERFACE_HYPERLINK_IMPL:
87 return g_atk_hyperlink_impl_type;
88 case MAI_INTERFACE_SELECTION:
89 return ATK_TYPE_SELECTION(atk_selection_get_type ());
90 case MAI_INTERFACE_TABLE:
91 return ATK_TYPE_TABLE(atk_table_get_type ());
92 case MAI_INTERFACE_TEXT:
93 return ATK_TYPE_TEXT(atk_text_get_type ());
94 case MAI_INTERFACE_DOCUMENT:
95 return ATK_TYPE_DOCUMENT(atk_document_get_type ());
96 case MAI_INTERFACE_IMAGE:
97 return ATK_TYPE_IMAGE(atk_image_get_type ());
98 case MAI_INTERFACE_TABLE_CELL:
99 MOZ_ASSERT(false)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { do { } while (
false); MOZ_ReportAssertionFailure("false", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 99); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")"); do
{ *((volatile int*)__null) = 99; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
100 }
101 return G_TYPE_INVALID((GType) ((0) << (2)));
102}
103
104#define NON_USER_EVENT":system" ":system"
105
106// The atk interfaces we can expose without checking what version of ATK we are
107// dealing with. At the moment AtkTableCell is the only interface we can't
108// always expose.
109static const GInterfaceInfo atk_if_infos[] = {
110 {(GInterfaceInitFunc)componentInterfaceInitCB,
111 (GInterfaceFinalizeFunc) nullptr, nullptr},
112 {(GInterfaceInitFunc)actionInterfaceInitCB,
113 (GInterfaceFinalizeFunc) nullptr, nullptr},
114 {(GInterfaceInitFunc)valueInterfaceInitCB, (GInterfaceFinalizeFunc) nullptr,
115 nullptr},
116 {(GInterfaceInitFunc)editableTextInterfaceInitCB,
117 (GInterfaceFinalizeFunc) nullptr, nullptr},
118 {(GInterfaceInitFunc)hypertextInterfaceInitCB,
119 (GInterfaceFinalizeFunc) nullptr, nullptr},
120 {(GInterfaceInitFunc)hyperlinkImplInterfaceInitCB,
121 (GInterfaceFinalizeFunc) nullptr, nullptr},
122 {(GInterfaceInitFunc)selectionInterfaceInitCB,
123 (GInterfaceFinalizeFunc) nullptr, nullptr},
124 {(GInterfaceInitFunc)tableInterfaceInitCB, (GInterfaceFinalizeFunc) nullptr,
125 nullptr},
126 {(GInterfaceInitFunc)textInterfaceInitCB, (GInterfaceFinalizeFunc) nullptr,
127 nullptr},
128 {(GInterfaceInitFunc)documentInterfaceInitCB,
129 (GInterfaceFinalizeFunc) nullptr, nullptr},
130 {(GInterfaceInitFunc)imageInterfaceInitCB, (GInterfaceFinalizeFunc) nullptr,
131 nullptr}};
132
133static GQuark quark_mai_hyperlink = 0;
134
135AtkHyperlink* MaiAtkObject::GetAtkHyperlink() {
136 NS_ASSERTION(quark_mai_hyperlink, "quark_mai_hyperlink not initialized")do { if (!(quark_mai_hyperlink)) { NS_DebugBreak(NS_DEBUG_ASSERTION
, "quark_mai_hyperlink not initialized", "quark_mai_hyperlink"
, "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 136); MOZ_PretendNoReturn(); } } while (0)
;
137 MaiHyperlink* maiHyperlink =
138 (MaiHyperlink*)g_object_get_qdata(G_OBJECT(this)((((GObject*) (void *) ((this))))), quark_mai_hyperlink);
139 if (!maiHyperlink) {
140 maiHyperlink = new MaiHyperlink(acc);
141 g_object_set_qdata(G_OBJECT(this)((((GObject*) (void *) ((this))))), quark_mai_hyperlink, maiHyperlink);
142 }
143
144 return maiHyperlink->GetAtkHyperlink();
145}
146
147void MaiAtkObject::Shutdown() {
148 acc = nullptr;
149 MaiHyperlink* maiHyperlink =
150 (MaiHyperlink*)g_object_get_qdata(G_OBJECT(this)((((GObject*) (void *) ((this))))), quark_mai_hyperlink);
151 if (maiHyperlink) {
4
Assuming 'maiHyperlink' is non-null
5
Taking true branch
152 delete maiHyperlink;
6
Memory is released
7
Calling 'operator delete'
153 g_object_set_qdata(G_OBJECT(this)((((GObject*) (void *) ((this))))), quark_mai_hyperlink, nullptr);
154 }
155}
156
157struct MaiAtkObjectClass {
158 AtkObjectClass parent_class;
159};
160
161static guint mai_atk_object_signals[LAST_SIGNAL] = {
162 0,
163};
164
165static void MaybeFireNameChange(AtkObject* aAtkObj, const nsString& aNewName);
166
167G_BEGIN_DECLSextern "C" {
168/* callbacks for MaiAtkObject */
169static void classInitCB(AtkObjectClass* aClass);
170static void initializeCB(AtkObject* aAtkObj, gpointer aData);
171static void finalizeCB(GObject* aObj);
172
173/* callbacks for AtkObject virtual functions */
174static const gchar* getNameCB(AtkObject* aAtkObj);
175/* getDescriptionCB is also used by image interface */
176const gchar* getDescriptionCB(AtkObject* aAtkObj);
177static AtkRole getRoleCB(AtkObject* aAtkObj);
178static AtkAttributeSet* getAttributesCB(AtkObject* aAtkObj);
179static const gchar* GetLocaleCB(AtkObject*);
180static AtkObject* getParentCB(AtkObject* aAtkObj);
181static gint getChildCountCB(AtkObject* aAtkObj);
182static AtkObject* refChildCB(AtkObject* aAtkObj, gint aChildIndex);
183static gint getIndexInParentCB(AtkObject* aAtkObj);
184static AtkStateSet* refStateSetCB(AtkObject* aAtkObj);
185static AtkRelationSet* refRelationSetCB(AtkObject* aAtkObj);
186
187/* the missing atkobject virtual functions */
188/*
189 static AtkLayer getLayerCB(AtkObject *aAtkObj);
190 static gint getMdiZorderCB(AtkObject *aAtkObj);
191 static void SetNameCB(AtkObject *aAtkObj,
192 const gchar *name);
193 static void SetDescriptionCB(AtkObject *aAtkObj,
194 const gchar *description);
195 static void SetParentCB(AtkObject *aAtkObj,
196 AtkObject *parent);
197 static void SetRoleCB(AtkObject *aAtkObj,
198 AtkRole role);
199 static guint ConnectPropertyChangeHandlerCB(
200 AtkObject *aObj,
201 AtkPropertyChangeHandler *handler);
202 static void RemovePropertyChangeHandlerCB(
203 AtkObject *aAtkObj,
204 guint handler_id);
205 static void InitializeCB(AtkObject *aAtkObj,
206 gpointer data);
207 static void ChildrenChangedCB(AtkObject *aAtkObj,
208 guint change_index,
209 gpointer changed_child);
210 static void FocusEventCB(AtkObject *aAtkObj,
211 gboolean focus_in);
212 static void PropertyChangeCB(AtkObject *aAtkObj,
213 AtkPropertyValues *values);
214 static void StateChangeCB(AtkObject *aAtkObj,
215 const gchar *name,
216 gboolean state_set);
217 static void VisibleDataChangedCB(AtkObject *aAtkObj);
218*/
219G_END_DECLS}
220
221static GType GetMaiAtkType(uint16_t interfacesBits);
222static const char* GetUniqueMaiAtkTypeName(uint16_t interfacesBits);
223
224static gpointer parent_class = nullptr;
225
226GType mai_atk_object_get_type(void) {
227 static GType type = 0;
228
229 if (!type) {
230 static const GTypeInfo tinfo = {
231 sizeof(MaiAtkObjectClass),
232 (GBaseInitFunc) nullptr,
233 (GBaseFinalizeFunc) nullptr,
234 (GClassInitFunc)classInitCB,
235 (GClassFinalizeFunc) nullptr,
236 nullptr, /* class data */
237 sizeof(MaiAtkObject), /* instance size */
238 0, /* nb preallocs */
239 (GInstanceInitFunc) nullptr,
240 nullptr /* value table */
241 };
242
243 type = g_type_register_static(ATK_TYPE_OBJECT(atk_object_get_type()), "MaiAtkObject", &tinfo,
244 GTypeFlags(0));
245 quark_mai_hyperlink = g_quark_from_static_string("MaiHyperlink");
246 }
247 return type;
248}
249
250AccessibleWrap::AccessibleWrap(nsIContent* aContent, DocAccessible* aDoc)
251 : LocalAccessible(aContent, aDoc), mAtkObject(nullptr) {}
252
253AccessibleWrap::~AccessibleWrap() {
254 NS_ASSERTION(!mAtkObject, "ShutdownAtkObject() is not called")do { if (!(!mAtkObject)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "ShutdownAtkObject() is not called"
, "!mAtkObject", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 254); MOZ_PretendNoReturn(); } } while (0)
;
255}
256
257void AccessibleWrap::ShutdownAtkObject() {
258 if (!mAtkObject) return;
259
260 NS_ASSERTION(IS_MAI_OBJECT(mAtkObject), "wrong type of atk object")do { if (!((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((mAtkObject)); GType __t = ((mai_atk_object_get_type()));
gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { NS_DebugBreak(NS_DEBUG_ASSERTION, "wrong type of atk object"
, "IS_MAI_OBJECT(mAtkObject)", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 260); MOZ_PretendNoReturn(); } } while (0)
;
261 if (IS_MAI_OBJECT(mAtkObject)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(mAtkObject)); GType __t = ((mai_atk_object_get_type())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))
) MAI_ATK_OBJECT(mAtkObject)((((MaiAtkObject*) (void *) ((mAtkObject)))))->Shutdown();
262
263 g_object_unref(mAtkObject);
264 mAtkObject = nullptr;
265}
266
267void AccessibleWrap::Shutdown() {
268 ShutdownAtkObject();
269 LocalAccessible::Shutdown();
270}
271
272void AccessibleWrap::GetNativeInterface(void** aOutAccessible) {
273 *aOutAccessible = nullptr;
274
275 if (!mAtkObject) {
276 if (IsDefunct() || IsText()) {
277 // We don't create ATK objects for node which has been shutdown or
278 // plain text leaves
279 return;
280 }
281
282 GType type = GetMaiAtkType(CreateMaiInterfaces());
283 if (!type) return;
284
285 mAtkObject = reinterpret_cast<AtkObject*>(g_object_new(type, nullptr));
286 if (!mAtkObject) return;
287
288 atk_object_initialize(mAtkObject, static_cast<Accessible*>(this));
289 mAtkObject->role = ATK_ROLE_INVALID;
290 mAtkObject->layer = ATK_LAYER_INVALID;
291 }
292
293 *aOutAccessible = mAtkObject;
294}
295
296AtkObject* AccessibleWrap::GetAtkObject(void) {
297 void* atkObj = nullptr;
298 GetNativeInterface(&atkObj);
299 return static_cast<AtkObject*>(atkObj);
300}
301
302// Get AtkObject from LocalAccessible interface
303/* static */
304AtkObject* AccessibleWrap::GetAtkObject(LocalAccessible* acc) {
305 void* atkObjPtr = nullptr;
306 acc->GetNativeInterface(&atkObjPtr);
307 return atkObjPtr ? ATK_OBJECT(atkObjPtr)((((AtkObject*) (void *) ((atkObjPtr))))) : nullptr;
308}
309
310/* private */
311uint16_t AccessibleWrap::CreateMaiInterfaces(void) {
312 uint16_t interfacesBits = 0;
313
314 // The Component interface is supported by all accessibles.
315 interfacesBits |= 1 << MAI_INTERFACE_COMPONENT;
316
317 // Add Action interface if the action count is more than zero.
318 if (ActionCount() > 0) interfacesBits |= 1 << MAI_INTERFACE_ACTION;
319
320 // Text, Editabletext, and Hypertext interface.
321 HyperTextAccessible* hyperText = AsHyperText();
322 if (hyperText && hyperText->IsTextRole()) {
323 interfacesBits |= 1 << MAI_INTERFACE_TEXT;
324 interfacesBits |= 1 << MAI_INTERFACE_EDITABLE_TEXT;
325 if (!nsAccUtils::MustPrune(this)) {
326 interfacesBits |= 1 << MAI_INTERFACE_HYPERTEXT;
327 }
328 }
329
330 // Value interface.
331 if (HasNumericValue()) interfacesBits |= 1 << MAI_INTERFACE_VALUE;
332
333 // Document interface.
334 if (IsDoc()) interfacesBits |= 1 << MAI_INTERFACE_DOCUMENT;
335
336 if (IsImage()) interfacesBits |= 1 << MAI_INTERFACE_IMAGE;
337
338 // HyperLink interface.
339 if (IsLink()) interfacesBits |= 1 << MAI_INTERFACE_HYPERLINK_IMPL;
340
341 if (!nsAccUtils::MustPrune(this)) { // These interfaces require children
342 // Table interface.
343 if (AsTable()) interfacesBits |= 1 << MAI_INTERFACE_TABLE;
344
345 if (AsTableCell()) interfacesBits |= 1 << MAI_INTERFACE_TABLE_CELL;
346
347 // Selection interface.
348 if (IsSelect()) {
349 interfacesBits |= 1 << MAI_INTERFACE_SELECTION;
350 }
351 }
352
353 return interfacesBits;
354}
355
356static GType GetMaiAtkType(uint16_t interfacesBits) {
357 GType type;
358 static const GTypeInfo tinfo = {
359 sizeof(MaiAtkObjectClass),
360 (GBaseInitFunc) nullptr,
361 (GBaseFinalizeFunc) nullptr,
362 (GClassInitFunc) nullptr,
363 (GClassFinalizeFunc) nullptr,
364 nullptr, /* class data */
365 sizeof(MaiAtkObject), /* instance size */
366 0, /* nb preallocs */
367 (GInstanceInitFunc) nullptr,
368 nullptr /* value table */
369 };
370
371 /*
372 * The members we use to register GTypes are GetAtkTypeForMai
373 * and atk_if_infos, which are constant values to each MaiInterface
374 * So we can reuse the registered GType when having
375 * the same MaiInterface types.
376 */
377 const char* atkTypeName = GetUniqueMaiAtkTypeName(interfacesBits);
378 type = g_type_from_name(atkTypeName);
379 if (type) {
380 return type;
381 }
382
383 /*
384 * gobject limits the number of types that can directly derive from any
385 * given object type to 4095.
386 */
387 static uint16_t typeRegCount = 0;
388 if (typeRegCount++ >= 4095) {
389 return G_TYPE_INVALID((GType) ((0) << (2)));
390 }
391 type = g_type_register_static(MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()), atkTypeName, &tinfo,
392 GTypeFlags(0));
393
394 for (uint32_t index = 0; index < ArrayLength(atk_if_infos); index++) {
395 if (interfacesBits & (1 << index)) {
396 g_type_add_interface_static(type,
397 GetAtkTypeForMai((MaiInterfaceType)index),
398 &atk_if_infos[index]);
399 }
400 }
401
402 // Special case AtkTableCell so we can check what version of Atk we are
403 // dealing with.
404 if (IsAtkVersionAtLeast(2, 12) &&
405 (interfacesBits & (1 << MAI_INTERFACE_TABLE_CELL))) {
406 const GInterfaceInfo cellInfo = {
407 (GInterfaceInitFunc)tableCellInterfaceInitCB,
408 (GInterfaceFinalizeFunc) nullptr, nullptr};
409 g_type_add_interface_static(type, gAtkTableCellGetTypeFunc(), &cellInfo);
410 }
411
412 return type;
413}
414
415static const char* GetUniqueMaiAtkTypeName(uint16_t interfacesBits) {
416#define MAI_ATK_TYPE_NAME_LEN(30) (30) /* 10+sizeof(uint16_t)*8/4+1 < 30 */
417
418 static gchar namePrefix[] = "MaiAtkType"; /* size = 10 */
419 static gchar name[MAI_ATK_TYPE_NAME_LEN(30) + 1];
420
421 SprintfLiteral(name, "%s%x", namePrefix, interfacesBits);
422 name[MAI_ATK_TYPE_NAME_LEN(30)] = '\0';
423
424 return name;
425}
426
427bool AccessibleWrap::IsValidObject() {
428 // to ensure we are not shut down
429 return !IsDefunct();
430}
431
432/* static functions for ATK callbacks */
433void classInitCB(AtkObjectClass* aClass) {
434 GObjectClass* gobject_class = G_OBJECT_CLASS(aClass)((((GObjectClass*) (void *) ((aClass)))));
435
436 parent_class = g_type_class_peek_parent(aClass);
437
438 aClass->get_name = getNameCB;
439 aClass->get_description = getDescriptionCB;
440 aClass->get_parent = getParentCB;
441 aClass->get_n_children = getChildCountCB;
442 aClass->ref_child = refChildCB;
443 aClass->get_index_in_parent = getIndexInParentCB;
444 aClass->get_role = getRoleCB;
445 aClass->get_attributes = getAttributesCB;
446 aClass->get_object_locale = GetLocaleCB;
447 aClass->ref_state_set = refStateSetCB;
448 aClass->ref_relation_set = refRelationSetCB;
449
450 aClass->initialize = initializeCB;
451
452 gobject_class->finalize = finalizeCB;
453
454 mai_atk_object_signals[ACTIVATE] = g_signal_new(
455 "activate", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()), G_SIGNAL_RUN_LAST,
456 0, /* default signal handler */
457 nullptr, nullptr, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE((GType) ((1) << (2))), 0);
458 mai_atk_object_signals[CREATE] = g_signal_new(
459 "create", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()), G_SIGNAL_RUN_LAST,
460 0, /* default signal handler */
461 nullptr, nullptr, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE((GType) ((1) << (2))), 0);
462 mai_atk_object_signals[DEACTIVATE] = g_signal_new(
463 "deactivate", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()), G_SIGNAL_RUN_LAST,
464 0, /* default signal handler */
465 nullptr, nullptr, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE((GType) ((1) << (2))), 0);
466 mai_atk_object_signals[DESTROY] = g_signal_new(
467 "destroy", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()), G_SIGNAL_RUN_LAST,
468 0, /* default signal handler */
469 nullptr, nullptr, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE((GType) ((1) << (2))), 0);
470 mai_atk_object_signals[MAXIMIZE] = g_signal_new(
471 "maximize", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()), G_SIGNAL_RUN_LAST,
472 0, /* default signal handler */
473 nullptr, nullptr, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE((GType) ((1) << (2))), 0);
474 mai_atk_object_signals[MINIMIZE] = g_signal_new(
475 "minimize", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()), G_SIGNAL_RUN_LAST,
476 0, /* default signal handler */
477 nullptr, nullptr, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE((GType) ((1) << (2))), 0);
478 mai_atk_object_signals[RESIZE] = g_signal_new(
479 "resize", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()), G_SIGNAL_RUN_LAST,
480 0, /* default signal handler */
481 nullptr, nullptr, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE((GType) ((1) << (2))), 0);
482 mai_atk_object_signals[RESTORE] = g_signal_new(
483 "restore", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()), G_SIGNAL_RUN_LAST,
484 0, /* default signal handler */
485 nullptr, nullptr, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE((GType) ((1) << (2))), 0);
486}
487
488void initializeCB(AtkObject* aAtkObj, gpointer aData) {
489 NS_ASSERTION((IS_MAI_OBJECT(aAtkObj)), "Invalid AtkObject")do { if (!(((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((aAtkObj)); GType __t = ((mai_atk_object_get_type())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))))) { NS_DebugBreak
(NS_DEBUG_ASSERTION, "Invalid AtkObject", "(IS_MAI_OBJECT(aAtkObj))"
, "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 489); MOZ_PretendNoReturn(); } } while (0)
;
490 NS_ASSERTION(aData, "Invalid Data to init AtkObject")do { if (!(aData)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Invalid Data to init AtkObject"
, "aData", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 490); MOZ_PretendNoReturn(); } } while (0)
;
491 if (!aAtkObj || !aData) return;
492
493 /* call parent init function */
494 /* AtkObjectClass has not a "initialize" function now,
495 * maybe it has later
496 */
497
498 if (ATK_OBJECT_CLASS(parent_class)((((AtkObjectClass*) (void *) ((parent_class)))))->initialize) {
499 ATK_OBJECT_CLASS(parent_class)((((AtkObjectClass*) (void *) ((parent_class)))))->initialize(aAtkObj, aData);
500 }
501
502 /* initialize object */
503 MAI_ATK_OBJECT(aAtkObj)((((MaiAtkObject*) (void *) ((aAtkObj)))))->acc = static_cast<Accessible*>(aData);
504}
505
506void finalizeCB(GObject* aObj) {
507 if (!IS_MAI_OBJECT(aObj)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(aObj)); GType __t = ((mai_atk_object_get_type())); gboolean __r
; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))
) return;
508 NS_ASSERTION(!MAI_ATK_OBJECT(aObj)->acc, "acc NOT null")do { if (!(!((((MaiAtkObject*) (void *) ((aObj)))))->acc))
{ NS_DebugBreak(NS_DEBUG_ASSERTION, "acc NOT null", "!MAI_ATK_OBJECT(aObj)->acc"
, "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 508); MOZ_PretendNoReturn(); } } while (0)
;
509
510 // call parent finalize function
511 // finalize of GObjectClass will unref the accessible parent if has
512 if (G_OBJECT_CLASS(parent_class)((((GObjectClass*) (void *) ((parent_class)))))->finalize) {
513 G_OBJECT_CLASS(parent_class)((((GObjectClass*) (void *) ((parent_class)))))->finalize(aObj);
514 }
515}
516
517const gchar* getNameCB(AtkObject* aAtkObj) {
518 nsAutoString name;
519 if (Accessible* acc = GetInternalObj(aAtkObj)) {
520 acc->Name(name);
521 } else {
522 return nullptr;
523 }
524
525 // XXX Firing an event from here does not seem right
526 MaybeFireNameChange(aAtkObj, name);
527
528 return aAtkObj->name;
529}
530
531static void MaybeFireNameChange(AtkObject* aAtkObj, const nsString& aNewName) {
532 NS_ConvertUTF16toUTF8 newNameUTF8(aNewName);
533 if (aAtkObj->name && !strcmp(aAtkObj->name, newNameUTF8.get())) return;
534
535 // Below we duplicate the functionality of atk_object_set_name(),
536 // but without calling atk_object_get_name(). Instead of
537 // atk_object_get_name() we directly access aAtkObj->name. This is because
538 // atk_object_get_name() would call getNameCB() which would call
539 // MaybeFireNameChange() (or atk_object_set_name() before this problem was
540 // fixed) and we would get an infinite recursion.
541 // See http://bugzilla.mozilla.org/733712
542
543 // Do not notify for initial name setting.
544 // See bug http://bugzilla.gnome.org/665870
545 bool notify = !!aAtkObj->name;
546
547 free(aAtkObj->name);
548 aAtkObj->name = strdup(newNameUTF8.get());
549
550 if (notify) g_object_notify(G_OBJECT(aAtkObj)((((GObject*) (void *) ((aAtkObj))))), "accessible-name");
551}
552
553const gchar* getDescriptionCB(AtkObject* aAtkObj) {
554 nsAutoString uniDesc;
555 if (Accessible* acc = GetInternalObj(aAtkObj)) {
556 acc->Description(uniDesc);
557 } else {
558 return nullptr;
559 }
560
561 NS_ConvertUTF8toUTF16 objDesc(aAtkObj->description);
562 if (!uniDesc.Equals(objDesc)) {
563 atk_object_set_description(aAtkObj, NS_ConvertUTF16toUTF8(uniDesc).get());
564 }
565
566 return aAtkObj->description;
567}
568
569AtkRole getRoleCB(AtkObject* aAtkObj) {
570 if (aAtkObj->role != ATK_ROLE_INVALID) return aAtkObj->role;
571
572 Accessible* acc = GetInternalObj(aAtkObj);
573 if (!acc) {
574 return ATK_ROLE_INVALID;
575 }
576
577#ifdef DEBUG1
578 if (AccessibleWrap* accWrap = GetAccessibleWrap(aAtkObj)) {
579 NS_ASSERTION(nsAccUtils::IsTextInterfaceSupportCorrect(accWrap),do { if (!(nsAccUtils::IsTextInterfaceSupportCorrect(accWrap)
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Does not support Text interface when it should"
, "nsAccUtils::IsTextInterfaceSupportCorrect(accWrap)", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 580); MOZ_PretendNoReturn(); } } while (0)
580 "Does not support Text interface when it should")do { if (!(nsAccUtils::IsTextInterfaceSupportCorrect(accWrap)
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Does not support Text interface when it should"
, "nsAccUtils::IsTextInterfaceSupportCorrect(accWrap)", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 580); MOZ_PretendNoReturn(); } } while (0)
;
581 }
582#endif
583
584#define ROLE(geckoRole, stringRole, ariaRole, atkRole, macRole, macSubrole, \
585 msaaRole, ia2Role, androidClass, iosIsElement, uiaControlType, \
586 nameRule) \
587 case roles::geckoRole: \
588 aAtkObj->role = atkRole; \
589 break;
590
591 switch (acc->Role()) {
592#include "RoleMap.h"
593 default:
594 MOZ_CRASH("Unknown role.")do { do { } while (false); MOZ_ReportCrash("" "Unknown role."
, "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 594); AnnotateMozCrashReason("MOZ_CRASH(" "Unknown role." ")"
); do { *((volatile int*)__null) = 594; __attribute__((nomerge
)) ::abort(); } while (false); } while (false)
;
595 }
596
597#undef ROLE
598
599 if (aAtkObj->role == ATK_ROLE_LIST_BOX && !IsAtkVersionAtLeast(2, 1)) {
600 aAtkObj->role = ATK_ROLE_LIST;
601 } else if (aAtkObj->role == ATK_ROLE_TABLE_ROW &&
602 !IsAtkVersionAtLeast(2, 1)) {
603 aAtkObj->role = ATK_ROLE_LIST_ITEM;
604 } else if (aAtkObj->role == ATK_ROLE_MATH && !IsAtkVersionAtLeast(2, 12)) {
605 aAtkObj->role = ATK_ROLE_SECTION;
606 } else if (aAtkObj->role == ATK_ROLE_COMMENT && !IsAtkVersionAtLeast(2, 12)) {
607 aAtkObj->role = ATK_ROLE_SECTION;
608 } else if (aAtkObj->role == ATK_ROLE_LANDMARK &&
609 !IsAtkVersionAtLeast(2, 12)) {
610 aAtkObj->role = ATK_ROLE_SECTION;
611 } else if (aAtkObj->role == ATK_ROLE_FOOTNOTE &&
612 !IsAtkVersionAtLeast(2, 25, 2)) {
613 aAtkObj->role = ATK_ROLE_SECTION;
614 } else if (aAtkObj->role == ATK_ROLE_STATIC && !IsAtkVersionAtLeast(2, 16)) {
615 aAtkObj->role = ATK_ROLE_TEXT;
616 } else if ((aAtkObj->role == ATK_ROLE_MATH_FRACTION ||
617 aAtkObj->role == ATK_ROLE_MATH_ROOT) &&
618 !IsAtkVersionAtLeast(2, 16)) {
619 aAtkObj->role = ATK_ROLE_SECTION;
620 } else if (aAtkObj->role == ATK_ROLE_MARK && !IsAtkVersionAtLeast(2, 36)) {
621 aAtkObj->role = ATK_ROLE_TEXT;
622 } else if (aAtkObj->role == ATK_ROLE_SUGGESTION &&
623 !IsAtkVersionAtLeast(2, 36)) {
624 aAtkObj->role = ATK_ROLE_SECTION;
625 } else if (aAtkObj->role == ATK_ROLE_COMMENT && !IsAtkVersionAtLeast(2, 36)) {
626 aAtkObj->role = ATK_ROLE_SECTION;
627 } else if ((aAtkObj->role == ATK_ROLE_CONTENT_DELETION ||
628 aAtkObj->role == ATK_ROLE_CONTENT_INSERTION) &&
629 !IsAtkVersionAtLeast(2, 34)) {
630 aAtkObj->role = ATK_ROLE_SECTION;
631 }
632
633 return aAtkObj->role;
634}
635
636static AtkAttributeSet* ConvertToAtkAttributeSet(AccAttributes* aAttributes) {
637 if (!aAttributes) {
638 return nullptr;
639 }
640
641 AtkAttributeSet* objAttributeSet = nullptr;
642
643 for (auto iter : *aAttributes) {
644 nsAutoString name;
645 iter.NameAsString(name);
646 if (name.Equals(u"placeholder")) {
647 name.AssignLiteral(u"placeholder-text");
648 }
649
650 nsAutoString value;
651 iter.ValueAsString(value);
652
653 AtkAttribute* objAttr = (AtkAttribute*)g_malloc(sizeof(AtkAttribute));
654 objAttr->name = g_strdup(NS_ConvertUTF16toUTF8(name).get())g_strdup_inline (NS_ConvertUTF16toUTF8(name).get());
655 objAttr->value = g_strdup(NS_ConvertUTF16toUTF8(value).get())g_strdup_inline (NS_ConvertUTF16toUTF8(value).get());
656 objAttributeSet = g_slist_prepend(objAttributeSet, objAttr);
657 }
658
659 // libspi will free it
660 return objAttributeSet;
661}
662
663AtkAttributeSet* getAttributesCB(AtkObject* aAtkObj) {
664 Accessible* acc = GetInternalObj(aAtkObj);
665 if (!acc) {
666 return nullptr;
667 }
668 RefPtr<AccAttributes> attributes = acc->Attributes();
669 return ConvertToAtkAttributeSet(attributes);
670}
671
672const gchar* GetLocaleCB(AtkObject* aAtkObj) {
673 Accessible* acc = GetInternalObj(aAtkObj);
674 if (!acc) {
675 return nullptr;
676 }
677
678 nsAutoString locale;
679 acc->Language(locale);
680 return AccessibleWrap::ReturnString(locale);
681}
682
683AtkObject* getParentCB(AtkObject* aAtkObj) {
684 if (aAtkObj->accessible_parent) return aAtkObj->accessible_parent;
685
686 Accessible* acc = GetInternalObj(aAtkObj);
687 if (!acc) {
688 return nullptr;
689 }
690
691 Accessible* parent = acc->Parent();
692 AtkObject* atkParent = parent ? GetWrapperFor(parent) : nullptr;
693 if (atkParent) atk_object_set_parent(aAtkObj, atkParent);
694
695 return aAtkObj->accessible_parent;
696}
697
698gint getChildCountCB(AtkObject* aAtkObj) {
699 Accessible* acc = GetInternalObj(aAtkObj);
700 if (!acc || nsAccUtils::MustPrune(acc)) {
701 return 0;
702 }
703 return static_cast<gint>(acc->EmbeddedChildCount());
704}
705
706AtkObject* refChildCB(AtkObject* aAtkObj, gint aChildIndex) {
707 // aChildIndex should not be less than zero
708 if (aChildIndex < 0) {
709 return nullptr;
710 }
711
712 Accessible* acc = GetInternalObj(aAtkObj);
713 if (!acc || nsAccUtils::MustPrune(acc)) {
714 return nullptr;
715 }
716 Accessible* accChild = acc->EmbeddedChildAt(aChildIndex);
717 if (!accChild) {
718 return nullptr;
719 }
720
721 AtkObject* childAtkObj = GetWrapperFor(accChild);
722 NS_ASSERTION(childAtkObj, "Fail to get AtkObj")do { if (!(childAtkObj)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "Fail to get AtkObj"
, "childAtkObj", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 722); MOZ_PretendNoReturn(); } } while (0)
;
723 if (!childAtkObj) {
724 return nullptr;
725 }
726
727 g_object_ref(childAtkObj);
728
729 if (aAtkObj != childAtkObj->accessible_parent) {
730 atk_object_set_parent(childAtkObj, aAtkObj);
731 }
732
733 return childAtkObj;
734}
735
736gint getIndexInParentCB(AtkObject* aAtkObj) {
737 // We don't use LocalAccessible::IndexInParent() because we don't include text
738 // leaf nodes as children in ATK.
739 Accessible* acc = GetInternalObj(aAtkObj);
740 if (!acc) {
741 return -1;
742 }
743 if (acc->IsDoc()) {
744 return 0;
745 }
746 Accessible* parent = acc->Parent();
747 if (!parent) {
748 return -1;
749 }
750 return parent->IndexOfEmbeddedChild(acc);
751}
752
753static void TranslateStates(uint64_t aState, roles::Role aRole,
754 AtkStateSet* aStateSet) {
755 // atk doesn't have a read only state so read only things shouldn't be
756 // editable. However, we don't do this for list items because Gecko always
757 // exposes those as read only.
758 if ((aState & states::READONLY) && aRole != roles::LISTITEM) {
759 aState &= ~states::EDITABLE;
760 }
761
762 // Convert every state to an entry in AtkStateMap
763 uint64_t bitMask = 1;
764 for (auto stateIndex = 0U; stateIndex < gAtkStateMapLen; stateIndex++) {
765 if (gAtkStateMap[stateIndex]
766 .atkState) { // There's potentially an ATK state for this
767 bool isStateOn = (aState & bitMask) != 0;
768 if (gAtkStateMap[stateIndex].stateMapEntryType == kMapOpposite) {
769 isStateOn = !isStateOn;
770 }
771 if (isStateOn) {
772 atk_state_set_add_state(aStateSet, gAtkStateMap[stateIndex].atkState);
773 }
774 }
775 bitMask <<= 1;
776 }
777}
778
779AtkStateSet* refStateSetCB(AtkObject* aAtkObj) {
780 AtkStateSet* state_set = nullptr;
781 state_set = ATK_OBJECT_CLASS(parent_class)((((AtkObjectClass*) (void *) ((parent_class)))))->ref_state_set(aAtkObj);
782
783 if (Accessible* acc = GetInternalObj(aAtkObj)) {
784 TranslateStates(acc->State(), acc->Role(), state_set);
785 } else {
786 TranslateStates(states::DEFUNCT, roles::NOTHING, state_set);
787 }
788
789 return state_set;
790}
791
792static void UpdateAtkRelation(RelationType aType, Accessible* aAcc,
793 AtkRelationType aAtkType,
794 AtkRelationSet* aAtkSet) {
795 if (aAtkType == ATK_RELATION_NULL) return;
796
797 AtkRelation* atkRelation =
798 atk_relation_set_get_relation_by_type(aAtkSet, aAtkType);
799 if (atkRelation) atk_relation_set_remove(aAtkSet, atkRelation);
800
801 Relation rel(aAcc->RelationByType(aType));
802 nsTArray<AtkObject*> targets;
803 Accessible* tempAcc = nullptr;
804 while ((tempAcc = rel.Next())) {
805 targets.AppendElement(GetWrapperFor(tempAcc));
806 }
807
808 if (targets.Length()) {
809 atkRelation =
810 atk_relation_new(targets.Elements(), targets.Length(), aAtkType);
811 atk_relation_set_add(aAtkSet, atkRelation);
812 g_object_unref(atkRelation);
813 }
814}
815
816AtkRelationSet* refRelationSetCB(AtkObject* aAtkObj) {
817 AtkRelationSet* relation_set =
818 ATK_OBJECT_CLASS(parent_class)((((AtkObjectClass*) (void *) ((parent_class)))))->ref_relation_set(aAtkObj);
819
820 Accessible* acc = GetInternalObj(aAtkObj);
821 if (!acc) {
822 return relation_set;
823 }
824
825#define RELATIONTYPE(geckoType, geckoTypeName, atkType, msaaType, ia2Type) \
826 UpdateAtkRelation(RelationType::geckoType, acc, atkType, relation_set);
827
828#include "RelationTypeMap.h"
829
830#undef RELATIONTYPE
831
832 return relation_set;
833}
834
835// Check if aAtkObj is a valid MaiAtkObject, and return the AccessibleWrap
836// for it.
837AccessibleWrap* GetAccessibleWrap(AtkObject* aAtkObj) {
838 NS_ENSURE_TRUE(IS_MAI_OBJECT(aAtkObj), nullptr)do { if ((__builtin_expect(!!(!((((__extension__ ({ GTypeInstance
*__inst = (GTypeInstance*) ((aAtkObj)); GType __t = ((mai_atk_object_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; })))))), 0))) { NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE("
"IS_MAI_OBJECT(aAtkObj)" ") failed", nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 838); return nullptr; } } while (false)
;
839
840 // If we're working with an ATK object, we need to convert the Accessible
841 // back to an AccessibleWrap:
842 Accessible* storedAcc = MAI_ATK_OBJECT(aAtkObj)((((MaiAtkObject*) (void *) ((aAtkObj)))))->acc;
843 if (!storedAcc) {
844 return nullptr;
845 }
846 auto* accWrap = static_cast<AccessibleWrap*>(storedAcc->AsLocal());
847
848 // Check if the accessible was deconstructed.
849 if (!accWrap) return nullptr;
850
851 NS_ENSURE_TRUE(accWrap->GetAtkObject() == aAtkObj, nullptr)do { if ((__builtin_expect(!!(!(accWrap->GetAtkObject() ==
aAtkObj)), 0))) { NS_DebugBreak(NS_DEBUG_WARNING, "NS_ENSURE_TRUE("
"accWrap->GetAtkObject() == aAtkObj" ") failed", nullptr,
"/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 851); return nullptr; } } while (false)
;
852
853 AccessibleWrap* appAccWrap = ApplicationAcc();
854 if (appAccWrap != accWrap && !accWrap->IsValidObject()) {
855 return nullptr;
856 }
857
858 return accWrap;
859}
860
861RemoteAccessible* GetProxy(AtkObject* aObj) {
862 Accessible* acc = GetInternalObj(aObj);
863 if (!acc) {
864 return nullptr;
865 }
866
867 return acc->AsRemote();
868}
869
870Accessible* GetInternalObj(AtkObject* aObj) {
871 if (!aObj || !IS_MAI_OBJECT(aObj)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(aObj)); GType __t = ((mai_atk_object_get_type())); gboolean __r
; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))
) return nullptr;
872
873 return MAI_ATK_OBJECT(aObj)((((MaiAtkObject*) (void *) ((aObj)))))->acc;
874}
875
876AtkObject* GetWrapperFor(Accessible* aAcc) {
877 if (!aAcc) {
878 return nullptr;
879 }
880
881 if (aAcc->IsRemote()) {
882 return reinterpret_cast<AtkObject*>(aAcc->AsRemote()->GetWrapper());
883 }
884
885 return AccessibleWrap::GetAtkObject(aAcc->AsLocal());
886}
887
888static uint16_t GetInterfacesForProxy(RemoteAccessible* aProxy) {
889 uint16_t interfaces = 1 << MAI_INTERFACE_COMPONENT;
890 if (aProxy->IsHyperText()) {
891 interfaces |= (1 << MAI_INTERFACE_HYPERTEXT) | (1 << MAI_INTERFACE_TEXT) |
892 (1 << MAI_INTERFACE_EDITABLE_TEXT);
893 }
894
895 if (aProxy->IsLink()) {
896 interfaces |= 1 << MAI_INTERFACE_HYPERLINK_IMPL;
897 }
898
899 if (aProxy->HasNumericValue()) {
900 interfaces |= 1 << MAI_INTERFACE_VALUE;
901 }
902
903 if (aProxy->IsTable()) {
904 interfaces |= 1 << MAI_INTERFACE_TABLE;
905 }
906
907 if (aProxy->IsTableCell()) {
908 interfaces |= 1 << MAI_INTERFACE_TABLE_CELL;
909 }
910
911 if (aProxy->IsImage()) {
912 interfaces |= 1 << MAI_INTERFACE_IMAGE;
913 }
914
915 if (aProxy->IsDoc()) {
916 interfaces |= 1 << MAI_INTERFACE_DOCUMENT;
917 }
918
919 if (aProxy->IsSelect()) {
920 interfaces |= 1 << MAI_INTERFACE_SELECTION;
921 }
922
923 if (aProxy->IsActionable()) {
924 interfaces |= 1 << MAI_INTERFACE_ACTION;
925 }
926
927 return interfaces;
928}
929
930void a11y::ProxyCreated(RemoteAccessible* aProxy) {
931 MOZ_ASSERT(aProxy->RemoteParent() || aProxy->IsDoc(),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aProxy->RemoteParent() || aProxy->IsDoc())>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aProxy->RemoteParent() || aProxy->IsDoc()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("aProxy->RemoteParent() || aProxy->IsDoc()"
" (" "Need parent to check for HyperLink interface" ")", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 932); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aProxy->RemoteParent() || aProxy->IsDoc()"
") (" "Need parent to check for HyperLink interface" ")"); do
{ *((volatile int*)__null) = 932; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
932 "Need parent to check for HyperLink interface")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(aProxy->RemoteParent() || aProxy->IsDoc())>
::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(aProxy->RemoteParent() || aProxy->IsDoc()))), 0
))) { do { } while (false); MOZ_ReportAssertionFailure("aProxy->RemoteParent() || aProxy->IsDoc()"
" (" "Need parent to check for HyperLink interface" ")", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 932); AnnotateMozCrashReason("MOZ_ASSERT" "(" "aProxy->RemoteParent() || aProxy->IsDoc()"
") (" "Need parent to check for HyperLink interface" ")"); do
{ *((volatile int*)__null) = 932; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
933 GType type = GetMaiAtkType(GetInterfacesForProxy(aProxy));
934 NS_ASSERTION(type, "why don't we have a type!")do { if (!(type)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "why don't we have a type!"
, "type", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 934); MOZ_PretendNoReturn(); } } while (0)
;
935
936 AtkObject* obj = reinterpret_cast<AtkObject*>(g_object_new(type, nullptr));
937 if (!obj) return;
938
939 atk_object_initialize(obj, static_cast<Accessible*>(aProxy));
940 obj->role = ATK_ROLE_INVALID;
941 obj->layer = ATK_LAYER_INVALID;
942 aProxy->SetWrapper(reinterpret_cast<uintptr_t>(obj));
943}
944
945void a11y::ProxyDestroyed(RemoteAccessible* aProxy) {
946 auto obj = reinterpret_cast<MaiAtkObject*>(aProxy->GetWrapper());
947 if (!obj) {
1
Assuming 'obj' is non-null
2
Taking false branch
948 return;
949 }
950
951 obj->Shutdown();
3
Calling 'MaiAtkObject::Shutdown'
952 g_object_unref(obj);
953 aProxy->SetWrapper(0);
954}
955
956void a11y::PlatformEvent(Accessible* aTarget, uint32_t aEventType) {
957 AtkObject* wrapper = GetWrapperFor(aTarget);
958
959 switch (aEventType) {
960 case nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE:
961 if (aTarget->IsDoc()) {
962 g_signal_emit_by_name(wrapper, "load_complete");
963 }
964 // XXX - Handle native dialog accessibles.
965 if (!aTarget->IsRoot() && aTarget->HasARIARole() &&
966 aTarget->Role() == roles::DIALOG) {
967 guint id = g_signal_lookup("activate", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()));
968 g_signal_emit(wrapper, id, 0);
969 }
970 break;
971 case nsIAccessibleEvent::EVENT_DOCUMENT_RELOAD:
972 if (aTarget->IsDoc()) {
973 g_signal_emit_by_name(wrapper, "reload");
974 }
975 break;
976 case nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_STOPPED:
977 if (aTarget->IsDoc()) {
978 g_signal_emit_by_name(wrapper, "load_stopped");
979 }
980 break;
981 case nsIAccessibleEvent::EVENT_MENUPOPUP_START:
982 atk_focus_tracker_notify(wrapper); // fire extra focus event
983 atk_object_notify_state_change(wrapper, ATK_STATE_VISIBLE, true);
984 atk_object_notify_state_change(wrapper, ATK_STATE_SHOWING, true);
985 break;
986 case nsIAccessibleEvent::EVENT_MENUPOPUP_END:
987 atk_object_notify_state_change(wrapper, ATK_STATE_VISIBLE, false);
988 atk_object_notify_state_change(wrapper, ATK_STATE_SHOWING, false);
989 break;
990 case nsIAccessibleEvent::EVENT_ALERT:
991 // A hack using state change showing events as alert events.
992 atk_object_notify_state_change(wrapper, ATK_STATE_SHOWING, true);
993 break;
994 case nsIAccessibleEvent::EVENT_VALUE_CHANGE:
995 case nsIAccessibleEvent::EVENT_TEXT_VALUE_CHANGE:
996 if (aTarget->HasNumericValue()) {
997 // Make sure this is a numeric value. Don't fire for string value
998 // changes (e.g. text editing) ATK values are always numeric.
999 g_object_notify((GObject*)wrapper, "accessible-value");
1000 }
1001 break;
1002 case nsIAccessibleEvent::EVENT_TEXT_SELECTION_CHANGED:
1003 g_signal_emit_by_name(wrapper, "text_selection_changed");
1004 break;
1005 case nsIAccessibleEvent::EVENT_SELECTION_WITHIN:
1006 g_signal_emit_by_name(wrapper, "selection_changed");
1007 break;
1008 case nsIAccessibleEvent::EVENT_TEXT_ATTRIBUTE_CHANGED:
1009 g_signal_emit_by_name(wrapper, "text-attributes-changed");
1010 break;
1011 case nsIAccessibleEvent::EVENT_NAME_CHANGE: {
1012 nsAutoString newName;
1013 aTarget->Name(newName);
1014 MaybeFireNameChange(wrapper, newName);
1015 break;
1016 }
1017 case nsIAccessibleEvent::EVENT_WINDOW_ACTIVATE: {
1018 guint id = g_signal_lookup("activate", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()));
1019 g_signal_emit(wrapper, id, 0);
1020 // Always fire a current focus event after activation.
1021 FocusMgr()->ForceFocusEvent();
1022 break;
1023 }
1024 case nsIAccessibleEvent::EVENT_WINDOW_DEACTIVATE: {
1025 guint id = g_signal_lookup("deactivate", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()));
1026 g_signal_emit(wrapper, id, 0);
1027 break;
1028 }
1029 case nsIAccessibleEvent::EVENT_WINDOW_MAXIMIZE: {
1030 guint id = g_signal_lookup("maximize", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()));
1031 g_signal_emit(wrapper, id, 0);
1032 break;
1033 }
1034 case nsIAccessibleEvent::EVENT_WINDOW_MINIMIZE: {
1035 guint id = g_signal_lookup("minimize", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()));
1036 g_signal_emit(wrapper, id, 0);
1037 break;
1038 }
1039 case nsIAccessibleEvent::EVENT_WINDOW_RESTORE: {
1040 guint id = g_signal_lookup("restore", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()));
1041 g_signal_emit(wrapper, id, 0);
1042 break;
1043 }
1044 }
1045}
1046
1047void a11y::PlatformStateChangeEvent(Accessible* aTarget, uint64_t aState,
1048 bool aEnabled) {
1049 MaiAtkObject* atkObj = MAI_ATK_OBJECT(GetWrapperFor(aTarget))((((MaiAtkObject*) (void *) ((GetWrapperFor(aTarget))))));
1050 atkObj->FireStateChangeEvent(aState, aEnabled);
1051}
1052
1053void a11y::PlatformFocusEvent(Accessible* aTarget,
1054 const LayoutDeviceIntRect& aCaretRect) {
1055 AtkObject* wrapper = GetWrapperFor(aTarget);
1056
1057 // XXX Do we really need this check? If so, do we need a similar check for
1058 // RemoteAccessible?
1059 if (LocalAccessible* localTarget = aTarget->AsLocal()) {
1060 a11y::RootAccessible* rootAcc = localTarget->RootAccessible();
1061 if (!rootAcc || !rootAcc->IsActivated()) {
1062 return;
1063 }
1064 }
1065
1066 atk_focus_tracker_notify(wrapper);
1067 atk_object_notify_state_change(wrapper, ATK_STATE_FOCUSED, true);
1068}
1069
1070void a11y::PlatformCaretMoveEvent(Accessible* aTarget, int32_t aOffset,
1071 bool aIsSelectionCollapsed,
1072 int32_t aGranularity,
1073 const LayoutDeviceIntRect& aCaretRect,
1074 bool aFromUser) {
1075 AtkObject* wrapper = GetWrapperFor(aTarget);
1076 g_signal_emit_by_name(wrapper, "text_caret_moved", aOffset);
1077}
1078
1079void MaiAtkObject::FireStateChangeEvent(uint64_t aState, bool aEnabled) {
1080 auto state = aState;
1081 int32_t stateIndex = -1;
1082 while (state > 0) {
1083 ++stateIndex;
1084 state >>= 1;
1085 }
1086
1087 MOZ_ASSERT(do { static_assert( mozilla::detail::AssertionConditionType<
decltype(stateIndex >= 0 && stateIndex < static_cast
<int32_t>(gAtkStateMapLen))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(stateIndex >= 0 &&
stateIndex < static_cast<int32_t>(gAtkStateMapLen))
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("stateIndex >= 0 && stateIndex < static_cast<int32_t>(gAtkStateMapLen)"
" (" "No ATK state for internal state was found" ")", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 1089); AnnotateMozCrashReason("MOZ_ASSERT" "(" "stateIndex >= 0 && stateIndex < static_cast<int32_t>(gAtkStateMapLen)"
") (" "No ATK state for internal state was found" ")"); do {
*((volatile int*)__null) = 1089; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
1088 stateIndex >= 0 && stateIndex < static_cast<int32_t>(gAtkStateMapLen),do { static_assert( mozilla::detail::AssertionConditionType<
decltype(stateIndex >= 0 && stateIndex < static_cast
<int32_t>(gAtkStateMapLen))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(stateIndex >= 0 &&
stateIndex < static_cast<int32_t>(gAtkStateMapLen))
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("stateIndex >= 0 && stateIndex < static_cast<int32_t>(gAtkStateMapLen)"
" (" "No ATK state for internal state was found" ")", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 1089); AnnotateMozCrashReason("MOZ_ASSERT" "(" "stateIndex >= 0 && stateIndex < static_cast<int32_t>(gAtkStateMapLen)"
") (" "No ATK state for internal state was found" ")"); do {
*((volatile int*)__null) = 1089; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
1089 "No ATK state for internal state was found")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(stateIndex >= 0 && stateIndex < static_cast
<int32_t>(gAtkStateMapLen))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(stateIndex >= 0 &&
stateIndex < static_cast<int32_t>(gAtkStateMapLen))
)), 0))) { do { } while (false); MOZ_ReportAssertionFailure("stateIndex >= 0 && stateIndex < static_cast<int32_t>(gAtkStateMapLen)"
" (" "No ATK state for internal state was found" ")", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 1089); AnnotateMozCrashReason("MOZ_ASSERT" "(" "stateIndex >= 0 && stateIndex < static_cast<int32_t>(gAtkStateMapLen)"
") (" "No ATK state for internal state was found" ")"); do {
*((volatile int*)__null) = 1089; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
1090 if (stateIndex < 0 || stateIndex >= static_cast<int32_t>(gAtkStateMapLen)) {
1091 return;
1092 }
1093
1094 if (gAtkStateMap[stateIndex].atkState != kNone) {
1095 MOZ_ASSERT(gAtkStateMap[stateIndex].stateMapEntryType != kNoStateChange,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(gAtkStateMap[stateIndex].stateMapEntryType != kNoStateChange
)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(gAtkStateMap[stateIndex].stateMapEntryType != kNoStateChange
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"gAtkStateMap[stateIndex].stateMapEntryType != kNoStateChange"
" (" "State changes should not fired for this state" ")", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 1096); AnnotateMozCrashReason("MOZ_ASSERT" "(" "gAtkStateMap[stateIndex].stateMapEntryType != kNoStateChange"
") (" "State changes should not fired for this state" ")"); do
{ *((volatile int*)__null) = 1096; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
1096 "State changes should not fired for this state")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(gAtkStateMap[stateIndex].stateMapEntryType != kNoStateChange
)>::isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(gAtkStateMap[stateIndex].stateMapEntryType != kNoStateChange
))), 0))) { do { } while (false); MOZ_ReportAssertionFailure(
"gAtkStateMap[stateIndex].stateMapEntryType != kNoStateChange"
" (" "State changes should not fired for this state" ")", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 1096); AnnotateMozCrashReason("MOZ_ASSERT" "(" "gAtkStateMap[stateIndex].stateMapEntryType != kNoStateChange"
") (" "State changes should not fired for this state" ")"); do
{ *((volatile int*)__null) = 1096; __attribute__((nomerge)) ::
abort(); } while (false); } } while (false)
;
1097
1098 if (gAtkStateMap[stateIndex].stateMapEntryType == kMapOpposite) {
1099 aEnabled = !aEnabled;
1100 }
1101
1102 // Fire state change for first state if there is one to map
1103 atk_object_notify_state_change(&parent, gAtkStateMap[stateIndex].atkState,
1104 aEnabled);
1105 }
1106}
1107
1108void a11y::PlatformTextChangeEvent(Accessible* aTarget, const nsAString& aStr,
1109 int32_t aStart, uint32_t aLen,
1110 bool aIsInsert, bool aFromUser) {
1111 MaiAtkObject* atkObj = MAI_ATK_OBJECT(GetWrapperFor(aTarget))((((MaiAtkObject*) (void *) ((GetWrapperFor(aTarget))))));
1112 atkObj->FireTextChangeEvent(aStr, aStart, aLen, aIsInsert, aFromUser);
1113}
1114
1115#define OLD_TEXT_INSERTED"text_changed::insert" "text_changed::insert"
1116#define OLD_TEXT_REMOVED"text_changed::delete" "text_changed::delete"
1117static const char* oldTextChangeStrings[2][2] = {
1118 {OLD_TEXT_REMOVED"text_changed::delete" NON_USER_EVENT":system", OLD_TEXT_INSERTED"text_changed::insert" NON_USER_EVENT":system"},
1119 {OLD_TEXT_REMOVED"text_changed::delete", OLD_TEXT_INSERTED"text_changed::insert"}};
1120
1121#define TEXT_INSERTED"text-insert" "text-insert"
1122#define TEXT_REMOVED"text-remove" "text-remove"
1123#define NON_USER_DETAIL"::system" "::system"
1124static const char* textChangedStrings[2][2] = {
1125 {TEXT_REMOVED"text-remove" NON_USER_DETAIL"::system", TEXT_INSERTED"text-insert" NON_USER_DETAIL"::system"},
1126 {TEXT_REMOVED"text-remove", TEXT_INSERTED"text-insert"}};
1127
1128void MaiAtkObject::FireTextChangeEvent(const nsAString& aStr, int32_t aStart,
1129 uint32_t aLen, bool aIsInsert,
1130 bool aFromUser) {
1131 if (gAvailableAtkSignals == eUnknown) {
1132 gAvailableAtkSignals = g_signal_lookup("text-insert", G_OBJECT_TYPE(this)(((((GTypeClass*) (((GTypeInstance*) (this))->g_class))->
g_type)))
)
1133 ? eHaveNewAtkTextSignals
1134 : eNoNewAtkSignals;
1135 }
1136
1137 if (gAvailableAtkSignals == eNoNewAtkSignals) {
1138 // XXX remove this code and the gHaveNewTextSignals check when we can
1139 // stop supporting old atk since it doesn't really work anyway
1140 // see bug 619002
1141 const char* signal_name = oldTextChangeStrings[aFromUser][aIsInsert];
1142 g_signal_emit_by_name(this, signal_name, aStart, aLen);
1143 } else {
1144 const char* signal_name = textChangedStrings[aFromUser][aIsInsert];
1145 g_signal_emit_by_name(this, signal_name, aStart, aLen,
1146 NS_ConvertUTF16toUTF8(aStr).get());
1147 }
1148}
1149
1150void a11y::PlatformShowHideEvent(Accessible* aTarget, Accessible* aParent,
1151 bool aInsert, bool aFromUser) {
1152 AtkObject* atkObj = GetWrapperFor(aTarget);
1153 if (!aInsert) {
1154 // XXX - Handle native dialog accessibles.
1155 if (!aTarget->IsRoot() && aTarget->HasARIARole() &&
1156 aTarget->Role() == roles::DIALOG) {
1157 guint id = g_signal_lookup("deactivate", MAI_TYPE_ATK_OBJECT(mai_atk_object_get_type()));
1158 g_signal_emit(atkObj, id, 0);
1159 }
1160 }
1161
1162 MaiAtkObject* obj = MAI_ATK_OBJECT(atkObj)((((MaiAtkObject*) (void *) ((atkObj)))));
1163 obj->FireAtkShowHideEvent(GetWrapperFor(aParent), aInsert, aFromUser);
1164}
1165
1166#define ADD_EVENT"children_changed::add" "children_changed::add"
1167#define HIDE_EVENT"children_changed::remove" "children_changed::remove"
1168
1169static const char* kMutationStrings[2][2] = {
1170 {HIDE_EVENT"children_changed::remove" NON_USER_EVENT":system", ADD_EVENT"children_changed::add" NON_USER_EVENT":system"},
1171 {HIDE_EVENT"children_changed::remove", ADD_EVENT"children_changed::add"},
1172};
1173
1174void MaiAtkObject::FireAtkShowHideEvent(AtkObject* aParent, bool aIsAdded,
1175 bool aFromUser) {
1176 if (!aParent) {
1177 // XXX ATK needs a parent for these events. However, we might have already
1178 // unbound from the parent by the time we fire a hide event. Ideally, we
1179 // need to find a way to keep the parent around, but ATK clients don't seem
1180 // to care about these missing events.
1181 MOZ_ASSERT(!aIsAdded)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(!aIsAdded)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(!aIsAdded))), 0))) { do { } while
(false); MOZ_ReportAssertionFailure("!aIsAdded", "/var/lib/jenkins/workspace/firefox-scan-build/accessible/atk/AccessibleWrap.cpp"
, 1181); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!aIsAdded" ")"
); do { *((volatile int*)__null) = 1181; __attribute__((nomerge
)) ::abort(); } while (false); } } while (false)
;
1182 return;
1183 }
1184 int32_t indexInParent = getIndexInParentCB(&this->parent);
1185 const char* signal_name = kMutationStrings[aFromUser][aIsAdded];
1186 g_signal_emit_by_name(aParent, signal_name, indexInParent, this, nullptr);
1187}
1188
1189void a11y::PlatformSelectionEvent(Accessible*, Accessible* aWidget, uint32_t) {
1190 MaiAtkObject* obj = MAI_ATK_OBJECT(GetWrapperFor(aWidget))((((MaiAtkObject*) (void *) ((GetWrapperFor(aWidget))))));
1191 g_signal_emit_by_name(obj, "selection_changed");
1192}
1193
1194// static
1195void AccessibleWrap::GetKeyBinding(Accessible* aAccessible,
1196 nsAString& aResult) {
1197 // Return all key bindings including access key and keyboard shortcut.
1198
1199 // Get access key.
1200 nsAutoString keyBindingsStr;
1201 KeyBinding keyBinding = aAccessible->AccessKey();
1202 if (!keyBinding.IsEmpty()) {
1203 keyBinding.AppendToString(keyBindingsStr, KeyBinding::eAtkFormat);
1204
1205 Accessible* parent = aAccessible->Parent();
1206 roles::Role role = parent ? parent->Role() : roles::NOTHING;
1207 if (role == roles::PARENT_MENUITEM || role == roles::MENUITEM ||
1208 role == roles::RADIO_MENU_ITEM || role == roles::CHECK_MENU_ITEM) {
1209 // It is submenu, expose keyboard shortcuts from menu hierarchy like
1210 // "s;<Alt>f:s"
1211 nsAutoString keysInHierarchyStr = keyBindingsStr;
1212 do {
1213 KeyBinding parentKeyBinding = parent->AccessKey();
1214 if (!parentKeyBinding.IsEmpty()) {
1215 nsAutoString str;
1216 parentKeyBinding.ToString(str, KeyBinding::eAtkFormat);
1217 str.Append(':');
1218
1219 keysInHierarchyStr.Insert(str, 0);
1220 }
1221 } while ((parent = parent->Parent()) && parent->Role() != roles::MENUBAR);
1222
1223 keyBindingsStr.Append(';');
1224 keyBindingsStr.Append(keysInHierarchyStr);
1225 }
1226 } else {
1227 // No access key, add ';' to point this.
1228 keyBindingsStr.Append(';');
1229 }
1230
1231 // Get keyboard shortcut.
1232 keyBindingsStr.Append(';');
1233 if (LocalAccessible* localAcc = aAccessible->AsLocal()) {
1234 keyBinding = localAcc->KeyboardShortcut();
1235 if (!keyBinding.IsEmpty()) {
1236 keyBinding.AppendToString(keyBindingsStr, KeyBinding::eAtkFormat);
1237 }
1238 }
1239 aResult = keyBindingsStr;
1240}
1241
1242// static
1243Accessible* AccessibleWrap::GetColumnHeader(TableAccessible* aAccessible,
1244 int32_t aColIdx) {
1245 if (!aAccessible) {
1246 return nullptr;
1247 }
1248
1249 Accessible* cell = aAccessible->CellAt(0, aColIdx);
1250 if (!cell) {
1251 return nullptr;
1252 }
1253
1254 // If the cell at the first row is column header then assume it is column
1255 // header for all rows,
1256 if (cell->Role() == roles::COLUMNHEADER) {
1257 return cell;
1258 }
1259
1260 // otherwise get column header for the data cell at the first row.
1261 TableCellAccessible* tableCell = cell->AsTableCell();
1262 if (!tableCell) {
1263 return nullptr;
1264 }
1265
1266 AutoTArray<Accessible*, 10> headerCells;
1267 tableCell->ColHeaderCells(&headerCells);
1268 if (headerCells.IsEmpty()) {
1269 return nullptr;
1270 }
1271
1272 return headerCells[0];
1273}
1274
1275// static
1276Accessible* AccessibleWrap::GetRowHeader(TableAccessible* aAccessible,
1277 int32_t aRowIdx) {
1278 if (!aAccessible) {
1279 return nullptr;
1280 }
1281
1282 Accessible* cell = aAccessible->CellAt(aRowIdx, 0);
1283 if (!cell) {
1284 return nullptr;
1285 }
1286
1287 // If the cell at the first column is row header then assume it is row
1288 // header for all columns,
1289 if (cell->Role() == roles::ROWHEADER) {
1290 return cell;
1291 }
1292
1293 // otherwise get row header for the data cell at the first column.
1294 TableCellAccessible* tableCell = cell->AsTableCell();
1295 if (!tableCell) {
1296 return nullptr;
1297 }
1298
1299 AutoTArray<Accessible*, 10> headerCells;
1300 tableCell->RowHeaderCells(&headerCells);
1301 if (headerCells.IsEmpty()) {
1302 return nullptr;
1303 }
1304
1305 return headerCells[0];
1306}

/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/mozilla/cxxalloc.h

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#ifndef mozilla_cxxalloc_h
6#define mozilla_cxxalloc_h
7
8/*
9 * We implement the default operators new/delete as part of
10 * libmozalloc, replacing their definitions in libstdc++. The
11 * operator new* definitions in libmozalloc will never return a NULL
12 * pointer.
13 *
14 * Each operator new immediately below returns a pointer to memory
15 * that can be delete'd by any of
16 *
17 * (1) the matching infallible operator delete immediately below
18 * (2) the matching system |operator delete(void*, std::nothrow)|
19 * (3) the matching system |operator delete(void*) noexcept(false)|
20 *
21 * NB: these are declared |noexcept(false)|, though they will never
22 * throw that exception. This declaration is consistent with the rule
23 * that |::operator new() noexcept(false)| will never return NULL.
24 *
25 * NB: mozilla::fallible can be used instead of std::nothrow.
26 */
27
28#ifndef MOZALLOC_EXPORT_NEW__attribute__((always_inline)) inline
29# define MOZALLOC_EXPORT_NEW__attribute__((always_inline)) inline MFBT_API__attribute__((weak)) __attribute__((visibility("default")))
30#endif
31
32MOZALLOC_EXPORT_NEW__attribute__((always_inline)) inline void* operator new(size_t size) noexcept(false) {
33 return moz_xmalloc(size);
34}
35
36MOZALLOC_EXPORT_NEW__attribute__((always_inline)) inline void* operator new(size_t size,
37 const std::nothrow_t&) noexcept(true) {
38 return malloc_implmalloc(size);
39}
40
41MOZALLOC_EXPORT_NEW__attribute__((always_inline)) inline void* operator new[](size_t size) noexcept(false) {
42 return moz_xmalloc(size);
43}
44
45MOZALLOC_EXPORT_NEW__attribute__((always_inline)) inline void* operator new[](size_t size,
46 const std::nothrow_t&) noexcept(true) {
47 return malloc_implmalloc(size);
48}
49
50MOZALLOC_EXPORT_NEW__attribute__((always_inline)) inline void operator delete(void* ptr) noexcept(true) {
51 return free_implfree(ptr);
8
Attempt to free released memory
52}
53
54MOZALLOC_EXPORT_NEW__attribute__((always_inline)) inline void operator delete(void* ptr,
55 const std::nothrow_t&) noexcept(true) {
56 return free_implfree(ptr);
57}
58
59MOZALLOC_EXPORT_NEW__attribute__((always_inline)) inline void operator delete[](void* ptr) noexcept(true) {
60 return free_implfree(ptr);
61}
62
63MOZALLOC_EXPORT_NEW__attribute__((always_inline)) inline void operator delete[](
64 void* ptr, const std::nothrow_t&) noexcept(true) {
65 return free_implfree(ptr);
66}
67
68#if defined(XP_WIN)
69// We provide the global sized delete overloads unconditionally because the
70// MSVC runtime headers do, despite compiling with /Zc:sizedDealloc-
71MOZALLOC_EXPORT_NEW__attribute__((always_inline)) inline void operator delete(void* ptr,
72 size_t /*size*/) noexcept(true) {
73 return free_implfree(ptr);
74}
75
76MOZALLOC_EXPORT_NEW__attribute__((always_inline)) inline void operator delete[](void* ptr,
77 size_t /*size*/) noexcept(true) {
78 return free_implfree(ptr);
79}
80#endif
81
82#endif /* mozilla_cxxalloc_h */